package com.it.rocketmp.controller;

import com.it.rocketmp.producer.sender.SenderService;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/testController")

public class TestController {
    @Autowired
    private SenderService senderService;
    @RequestMapping("/syncSend01")
    public String syncSend01(@RequestParam String data){

        SendResult sendResult = senderService.syncSend(data);

        System.out.println( "MsgId:"+sendResult.getMsgId());
        return "ok";
    }
    @RequestMapping("/asyncSend01")
    public String asyncSend01(@RequestParam String data){

         senderService.asyncSend(data,new SendCallback(){
            @Override
            public void onSuccess(SendResult sendResult) {
                System.out.println( "消息发送成功:"+sendResult.getMsgId());
            }

            @Override
            public void onException(Throwable e) {
                System.out.println( "消息发送失败:"+e.getMessage());
            }
        });
        return "ok";
    }
}
